package com.zdxlz.fcmp.upms.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdxlz.fcmp.common.core.util.R;
import com.zdxlz.fcmp.upms.api.entity.ExternalPlatformConfig;
import com.zdxlz.fcmp.upms.api.service.IExternalPlatformConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统对外部平台提供的凭证信息 前端控制器
 * </p>
 *
 * @author: aman
 * @since 2025-02-01
 */
@RestController
@AllArgsConstructor
@Tag(name = "凭证信息管理模块")
@RequestMapping("/api/v1/sys/external/platform")
public class ExternalPlatformConfigController {
    private IExternalPlatformConfigService externalPlatformConfigService;

    @GetMapping
    @Operation(summary = "分页查询凭证信息")
    public R getList(@ParameterObject Page page, @ParameterObject ExternalPlatformConfig entity) {
        return R.ok(externalPlatformConfigService.getConfigWithPage(page, entity));
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询单个凭证信息")
    public R getById(@PathVariable Long id) {
        return R.ok(externalPlatformConfigService.getById(id));
    }

    @PostMapping
    @Operation(summary = "新增凭证信息")
    public R create(@RequestBody ExternalPlatformConfig entity) {
        return R.ok(externalPlatformConfigService.save(entity));
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新凭证信息")
    public R update(@PathVariable Integer id, @RequestBody ExternalPlatformConfig entity) {
        entity.setId(id);
        return R.ok(externalPlatformConfigService.updateById(entity));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除凭证信息")
    public R delete(@PathVariable Long id) {
        return R.ok(externalPlatformConfigService.removeById(id));
    }

    @PostMapping("/secret")
    @Operation(summary = "生成凭证信息KEY")
    public R generateKey() {
        return R.ok(externalPlatformConfigService.generateKey());
    }
}
